package astar

import "math"

type Cell struct {
	X int8
	Y int8

	G int
	H int

	FatherCell *Cell
	// 状态  1.open  2.close 3.忽略
	State int8
}

func InitCell(aStar *Astar, x, y int8) *Cell {
	return &Cell{
		X: x,
		Y: y,

		G: aStar.ThisP.G + 1,
		H: getH(aStar, x, y),

		FatherCell: aStar.ThisP,
		State:      1,
	}
}

func getH(astar *Astar, x, y int8) int {
	endX, endY := astar.int2xy(astar.End)
	return int(math.Abs(float64(endX-x)) + math.Abs(float64(endY-y)))
}

func getH1(astar *Astar, x, y int8) int {
	endX, endY := astar.int2xy(astar.End)
	return int(math.Sqrt(math.Abs(float64(endX-x) * math.Abs(float64(endX-x)+math.Abs(float64(endY-y))*math.Abs(float64(endY-y))))))
}
